package com.chmingx.crud.config;

import com.chmingx.crud.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CrudWebConfig implements WebMvcConfigurer{
    @Autowired
    RedisUrlCountInterceptor redisUrlCountInterceptor;

    /**
     * Filter与Interceptor具有几乎相同功能，二者区别：
     * 1. Filter时Servlet定义的原生组件，脱离了Spring应用也能使用
     * 2. Interceptor时Spring定义的接口，可以使用Spring的自动装配等功能
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(redisUrlCountInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**", "/js/**");
    }
}
